package maskedpixel.ogmo.utils
{
	/**
	 * ...
	 * @author Erin M Gunn
	 */
	public final class OgmoValue
	{
		/**
		 * Describes the integer Ogmo value type.
		 */
		public static const INTEGER:String = "integer";
		
		/**
		 * Describes the number Ogmo value type.
		 */
		public static const NUMBER:String = "number";
		
		/**
		 * Describes the boolean Ogmo value type.
		 */
		public static const BOOLEAN:String = "boolean";
		
		/**
		 * Describes the string Ogmo value type.
		 */
		public static const STRING:String = "string";
		
		/**
		 * Describes the text Ogmo value type.
		 */
		public static const TEXT:String = "text";
		
		/**
		 * Any of the valid types for an Ogmo value.
		 */
		public var type:String;
		
		/**
		 * Name of this value.
		 */
		public var name:String;
		
		/**
		 * Default vaule of this Ogmo value.
		 */
		public var def:Object;
		
		/**
		 * The maximum value of this Ogmo value.  Only used for: integer, number, string and text.
		 */
		public var max:Number;
		
		/**
		 * The minimum value of this Ogmo value.  Only used for: integer and number.
		 */
		public var min:Number;
		
		/**
		 * A value used in the ogmo proejct files.
		 * @param	type	Any of the valid types: INTEGER, NUMBER, BOOLEAN, STRING, TEXT.
		 * Use the static constants provided by the OgmoValue class.
		 * @param	name	The name of the value to register.
		 * @param	def		Default value. Used for all.
		 * @param	max		Maximum value. Only used for: integer, number, string, text.
		 * @param	min		Minimum value. Only used for: integer, number.
		 */
		public function OgmoValue(type:String, name:String, def:String,  max:Number = 0, min:Number = 0) 
		{
			this.type = type;
			this.name = name;
			this.min = min;
			this.max = max;
			this.def = def;
		}
		
		/**
		 * Generates the XML representing this Value in an Ogmo Project.
		 * @return
		 */
		public function generateXML():XML
		{
			var xml:XML = new XML();
			xml = <{type}/>;
			xml.@name = name;
			xml.@default = def;
			if (type == BOOLEAN)	return xml;
			if (type == STRING || type == TEXT)
			{
				xml.@maxChars = max;
				return xml;
			}
			xml.@max = max;
			xml.@min = min;
			return xml;
		}
	}
}